﻿using System.Security.Cryptography;
using System.Text;

namespace YWM.Common.DataEncryptions
{
    public class MD5Encryption
    {
        /// <summary>
        /// MD5加密
        /// </summary>
        /// <param name="value"></param>
        /// <param name="format">
        ///  //X2和x2表示不省略首位为0的十六进制数字；
        /// </param>
        /// <returns></returns>
        public static string Encrypt(string value, string format = "x2")
        {
            MD5 md5 = MD5.Create();
            byte[] buffer = Encoding.Default.GetBytes(value);
            byte[] md5buffer = md5.ComputeHash(buffer);
            string encryptValue = string.Empty;
            foreach (byte b in md5buffer)
            {
                encryptValue += b.ToString(format);
            }
            return encryptValue;
        }
    }
}